package o7deletesamenumber;

import o3rome.Rome01;

/**
 * @author shkstart
 * @create 2021-12-31-21:18
 */
/*
*
* 将一个升序的数组中相同的元素剔除，并返回数组中剩余元素个数
*
* */
public class DeleteSameNumber {

    public static void main(String[] args) {

        int[] nums = {1, 1, 1, 2, 2, 3, 4, 5};

        int number = removeDuplicates(nums);


        for (int i = 0; i < number; i++) {
            System.out.println(nums[i]);
        }
    }


    public static int removeDuplicates(int[] nums) {

        int sign = 0;

        for (int i = 0; i < nums.length; i++) {
            nums[sign++] = nums[i];
            try {
                while (nums[i+1]==nums[i]) {
                    i++;
                }
            } catch (Exception e) {
                break;
            }
        }
        return sign;
    }

}
